home *** CD-ROM | disk | FTP | other *** search
/ 3D Game Programming All in One / 3D Game Programming All in One Disc.iso / 3D2E / RESOURCES / KOOB / common / ui / ColorPickerDlg.gui < prev    next >
Text File  |  2005-11-23  |  8KB  |  276 lines

  1. //--- OBJECT WRITE BEGIN ---
  2. new GuiColorPickerCtrl(ColorPickerDlg) {
  3.    Profile = "GuiDefaultProfile";
  4.    HorizSizing = "right";
  5.    VertSizing = "bottom";
  6.    position = "0 0";
  7.    Extent = "800 600";
  8.    MinExtent = "8 2";
  9.    Visible = "1";
  10.    baseColor = "1.000000 0.000000 1.000000 1.000000";
  11.    pickColor = "0.788235 0.713726 0.600000 1.000000";
  12.    selectorGap = "1";
  13.    displayMode = "Dropper";
  14.    actionOnMove = "1";
  15.  
  16.    new GuiWindowCtrl(GuiPickerDlg) {
  17.       Profile = "GuiWindowProfile";
  18.       HorizSizing = "right";
  19.       VertSizing = "bottom";
  20.       position = "51 39";
  21.       Extent = "358 294";
  22.       MinExtent = "8 2";
  23.       Visible = "1";
  24.       text = "Pick Color";
  25.       maxLength = "255";
  26.       resizeWidth = "0";
  27.       resizeHeight = "0";
  28.       canMove = "1";
  29.       canClose = "1";
  30.       canMinimize = "0";
  31.       canMaximize = "0";
  32.       MinSize = "50 50";
  33.       closeCommand = "endColorDropper();Canvas.popDialog(ColorPickerDlg);";
  34.  
  35.       new GuiColorPickerCtrl(ColorBlendSelect) {
  36.          Profile = "GuiDefaultProfile";
  37.          HorizSizing = "right";
  38.          VertSizing = "bottom";
  39.          position = "9 42";
  40.          Extent = "314 190";
  41.          MinExtent = "8 2";
  42.          Visible = "1";
  43.          baseColor = "0.600000 1.000000 0.000000 1.000000";
  44.          selectorGap = "1";
  45.          displayMode = "BlendColor";
  46.          actionOnMove = "1";
  47.       };
  48.       new GuiSliderCtrl(ColorAlphaSelect) {
  49.          Profile = "GuiSliderProfile";
  50.          HorizSizing = "right";
  51.          VertSizing = "bottom";
  52.          position = "8 238";
  53.          Extent = "293 21";
  54.          MinExtent = "8 2";
  55.          Visible = "1";
  56.          range = "0.000000 1.000000";
  57.          ticks = "255";
  58.          value = "1";
  59.       };
  60.       new GuiColorPickerCtrl(ColorRangeSelect) {
  61.          Profile = "GuiDefaultProfile";
  62.          HorizSizing = "right";
  63.          VertSizing = "bottom";
  64.          position = "328 42";
  65.          Extent = "21 188";
  66.          MinExtent = "8 2";
  67.          Visible = "1";
  68.          Command = "updatePickerBaseColor();";
  69.          baseColor = "1.000000 0.000000 1.000000 1.000000";
  70.          pickColor = "0.600000 1.000000 0.000000 1.000000";
  71.          selectorGap = "1";
  72.          displayMode = "VertColor";
  73.          actionOnMove = "1";
  74.       };
  75.       new GuiTextCtrl(Channel_R_Val) {
  76.          Profile = "GuiTextProfile";
  77.          HorizSizing = "right";
  78.          VertSizing = "bottom";
  79.          position = "14 21";
  80.          Extent = "22 18";
  81.          MinExtent = "8 2";
  82.          Visible = "1";
  83.          text = "R : 1.0";
  84.          maxLength = "255";
  85.       };
  86.       new GuiTextCtrl(Channel_G_Val) {
  87.          Profile = "GuiTextProfile";
  88.          HorizSizing = "right";
  89.          VertSizing = "bottom";
  90.          position = "69 21";
  91.          Extent = "23 18";
  92.          MinExtent = "8 2";
  93.          Visible = "1";
  94.          text = "G : 1.0";
  95.          maxLength = "255";
  96.       };
  97.       new GuiTextCtrl(Channel_B_Val) {
  98.          Profile = "GuiTextProfile";
  99.          HorizSizing = "right";
  100.          VertSizing = "bottom";
  101.          position = "131 21";
  102.          Extent = "22 18";
  103.          MinExtent = "8 2";
  104.          Visible = "1";
  105.          text = "B : 1.0";
  106.          maxLength = "255";
  107.       };
  108.       new GuiTextCtrl(Channel_A_Val) {
  109.          Profile = "GuiTextProfile";
  110.          HorizSizing = "right";
  111.          VertSizing = "bottom";
  112.          position = "198 21";
  113.          Extent = "23 18";
  114.          MinExtent = "8 2";
  115.          Visible = "1";
  116.          text = "A : 1.0";
  117.          maxLength = "255";
  118.       };
  119.       new GuiButtonCtrl() {
  120.          Profile = "GuiButtonProfile";
  121.          HorizSizing = "right";
  122.          VertSizing = "bottom";
  123.          position = "304 238";
  124.          Extent = "47 18";
  125.          MinExtent = "8 2";
  126.          Visible = "1";
  127.          Command = "toggleColorPicker();";
  128.          text = "Drop";
  129.          groupNum = "-1";
  130.          buttonType = "PushButton";
  131.       };
  132.       new GuiButtonCtrl() {
  133.          Profile = "GuiButtonProfile";
  134.          HorizSizing = "right";
  135.          VertSizing = "bottom";
  136.          position = "201 267";
  137.          Extent = "71 17";
  138.          MinExtent = "8 2";
  139.          Visible = "1";
  140.          Command = "DoColorPickerCallback();";
  141.          text = "Ok";
  142.          groupNum = "-1";
  143.          buttonType = "PushButton";
  144.       };
  145.       new GuiButtonCtrl() {
  146.          Profile = "GuiButtonProfile";
  147.          HorizSizing = "right";
  148.          VertSizing = "bottom";
  149.          position = "279 267";
  150.          Extent = "71 17";
  151.          MinExtent = "8 2";
  152.          Visible = "1";
  153.          Command = "Canvas.popDialog(ColorPickerDlg);";
  154.          text = "Cancel";
  155.          groupNum = "-1";
  156.          buttonType = "PushButton";
  157.       };
  158.    };
  159. };
  160. //--- OBJECT WRITE END ---
  161.  
  162. $ColorPickerCallback = ""; // Control that we need to update
  163. $ColorCallbackType   = 1;  // ColorI
  164.  
  165. // This function pushes the color picker dialog and returns to a callback the selected value
  166. function GetColorI( %currentColor, %callback )
  167. {
  168.    $ColorPickerCallback = %callback;
  169.    $ColorCallbackType = 1; // ColorI
  170.    
  171.    // Set the RGBA displays accordingly
  172.    %red = getWord(%currentColor, 0);
  173.    %green = getWord(%currentColor, 1);
  174.    %blue = getWord(%currentColor, 2);
  175.    %alpha = getWord(%currentColor, 3);
  176.    
  177.    setColorInfo(%red, %green, %blue, %alpha);
  178.    
  179.    ColorBlendSelect.pickColor = %red SPC %green SPC %blue SPC "1.0";
  180.    ColorBlendSelect.updateColor();
  181.    ColorAlphaSelect.setValue(%alpha);
  182.  
  183.    Canvas.pushDialog(ColorPickerDlg);
  184. }
  185.  
  186. function GetColorF( %currentColor, %callback )
  187. {
  188.    $ColorPickerCallback = %callback;
  189.    $ColorCallbackType = 2; // ColorF
  190.    
  191.    // Set the RGBA displays accordingly
  192.    %red = getWord(%currentColor, 0);
  193.    %green = getWord(%currentColor, 1);
  194.    %blue = getWord(%currentColor, 2);
  195.    %alpha = getWord(%currentColor, 3);
  196.  
  197.    setColorInfo(%red, %green, %blue, %alpha);
  198.  
  199.    ColorBlendSelect.pickColor = %red SPC %green SPC %blue SPC "1.0";
  200.    ColorBlendSelect.updateColor();
  201.    ColorAlphaSelect.setValue(%alpha);
  202.  
  203.    Canvas.pushDialog(ColorPickerDlg);
  204. }
  205.  
  206.  
  207. function DoColorPickerCallback()
  208. {
  209.   eval( $ColorPickerCallback @ "(\"" @ constructNewColor(ColorBlendSelect.getValue(), $ColorCallbackType) @"\");" );
  210.  
  211.   Canvas.popDialog(ColorPickerDlg);
  212. }   
  213.  
  214. // This function updates the base color on the blend control
  215. function updatePickerBaseColor()
  216. {
  217.    %pickColor = ColorRangeSelect.getValue();
  218.    %red = getWord(%pickColor, 0);
  219.    %green = getWord(%pickColor, 1);
  220.    %blue = getWord(%pickColor, 2);
  221.  
  222.    ColorBlendSelect.baseColor = %red SPC %green SPC %blue SPC "1.0";
  223.    ColorBlendSelect.updateColor();
  224. }
  225.  
  226. // This function is used to update the text controls at the top
  227. function setColorInfo(%red, %green, %blue, %alpha)
  228. {
  229.    Channel_R_Val.setValue("R :" SPC mCeil(%red * 255));
  230.    Channel_G_Val.setValue("G :" SPC mCeil(%green * 255));
  231.    Channel_B_Val.setValue("B :" SPC mCeil(%blue * 255));
  232.    Channel_A_Val.setValue("A :" SPC mCeil(%alpha * 255));
  233. }
  234.  
  235. // This function constructs a new color, and updates the text displays accordingly
  236. function constructNewColor(%pickColor, %colorType )
  237. {
  238.    %red = getWord(%pickColor, 0);
  239.    %green = getWord(%pickColor, 1);
  240.    %blue = getWord(%pickColor, 2);
  241.    %alpha = ColorAlphaSelect.getValue();
  242.    
  243.    // Update the text controls to reflect new color
  244.    setColorInfo(%red, %green, %blue, %alpha);
  245.    if ( %colorType == 1 ) // ColorI
  246.       return mCeil( %red * 255 ) SPC mCeil( %green * 255 ) SPC mCeil( %blue * 255 ) SPC mCeil( %alpha * 255 );
  247.    else // ColorF
  248.       return %red SPC %green SPC %blue SPC %alpha;
  249. }
  250.  
  251.  
  252. // Functions to deal with the color dropper
  253. function startColorDropper()
  254. {
  255.    //ColorPickerDlg.command = "ColorDropperSelect.baseColor = ColorPickerDlg.pickColor;";
  256.    ColorPickerDlg.altCommand = $pickerUpdateControl@".setValue(constructNewColor(ColorPickerDlg.pickColor));endColorDropper();";
  257.    ColorPickerDlg.setActive(true);
  258.    $pickerActive = true;
  259. }
  260.  
  261. function endColorDropper()
  262. {
  263.    ColorPickerDlg.command = "";
  264.    ColorPickerDlg.altCommand = "";
  265.    ColorPickerDlg.setActive(false);
  266.    $pickerActive = false;
  267. }
  268.  
  269. function toggleColorPicker()
  270. {
  271.    if ($pickerActive)
  272.       endColorDropper();
  273.    else
  274.       startColorDropper();
  275. }
  276.